<template>
	<view class="content">
		<view class="person_data">
			<!-- 头像 -->
			 <!-- #ifdef H5 -->
			<view class="data_img" >
				<image :src="userInfo.wxchatInfo.headimgurl"></image>
			</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view class="data_img" >
				<image :src="userInfo.wechatInfo.headimgurl"></image>
			</view>
			<!-- #endif -->
			<!-- 信息 -->
			<view class="data_info">
				
				 <!-- #ifdef H5 -->
				<view class="data_info_item">
				<text class="nickname">昵称</text>
				<!-- <input type="text" maxlength="20" placeholder="取个名字吧 (20个字符以内)" v-model="nickname"> -->
					<text class="user_name">{{userInfo.wxchatInfo.nickname}}</text>
			</view>
				<!-- #endif -->
					
				<!-- #ifdef MP-WEIXIN -->
				<view class="data_info_item">
					<text class="nickname">昵称</text>
					<!-- <input type="text" maxlength="20" placeholder="取个名字吧 (20个字符以内)" v-model="nickname"> -->
						<text class="user_name">{{userInfo.wechatInfo.nickname}}</text>
				</view>
					<!-- #endif -->
				
				<view class="data_info_item">
					<text class="nickname">姓名</text>
					<text class="user_name">{{userInfo.truename}}</text>
				</view>
				<view class="data_info_item">
					<!-- <text class="communityname">小区信息</text>
					<text class="community_name">{{userInfo.community_name}}{{userInfo.community_area_name}}{{userInfo.room_number}}</text> -->
					<text class="nickname">小区信息</text>
					<text class="user_name">{{userInfo.community_name}}{{userInfo.community_area_name}}{{userInfo.room_number}}</text>
				</view>
				<view class="data_info_item">
					<text class="nickname">绑定电表</text>
					<text class="user_name">{{userInfo.elc_code||'未绑定'}}</text>
				</view>
				<view class="data_info_item">
					<text class="nickname">绑定水表</text>
					<text class="user_name">{{userInfo.water_code||'未绑定'}}</text>
				</view>
			</view>
			<!-- <view class="save_btn" @click="preserve"> 
				<text>保 存</text>
			</view> -->
			<view class="ewm_box">
				<view class="ewm_box_txt">扫一扫帮你缴费</view>
				<image  class="ewm_box_img" :src="userInfo.user_img"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '../../static/util.js'
	export default {
		data() {
			return {
				imgUrl:util.globalData.imgPre,
				userInfo:'',
				nickname:'',
				ewmhead:'',
				
				var:""
			};
		},
		onLoad(info) { 
		  var that=this; 
		  
		},
		mounted() {
			var that=this;
			that.ajax({
				url:'api/user/getUserInfo',
				success:function(res){ 
					that.userInfo=res.data; 
					console.log(that.userInfo)
					
					
					that.ewmurl=that.userInfo.user_img
					console.log(that.ewmurl)
					
				}
			  }) 
		},
		methods:{
			preserve(){
				   this.ajax({
					url:'api/user/changeNickname',
					data:{
						nickname:this.nickname, 
					},
					success:function(res){
						if(res.code==200){
							uni.showToast({
								title:"修改成功",
								icon:'none'
							});
							
							
							setTimeout(() => {
								uni.navigateBack()
							}, 1000)
							
						}else{
							uni.showToast({
								title:"" + res.msg,
								icon:'none'
							});
						}
					}
				  })
			},
			uploadImg(){
				var that=this;
					uni.chooseImage({
					count: 1, //默认9
					sourceType:['album','camera'],
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					success: (res) =>{ 
						this.$upload({
							path:res.tempFilePaths[0],
							success:function success(res2){
								console.log(res2)
								//保存头像
								uni.showToast({
										title:'上传成功'
									});
							},
							fail:function fail(res2){
								console.log(res2)
								uni.showToast({
										title:'请稍后再试',
										icon:'none'
									});
							},
							complete:function complete(){
								console.log(111)
							}
						})
					},
					fail(res){
					console.log(res);	
					// uni.showToast({
					// 		title: '上传失败',
					// 		icon:'none'
					// 	});
					}
				});
			}
		}
	}
</script>

<style lang="less">

	.person_data{ 
		padding: 32rpx 0 0 33rpx; 
		.data_img{
			position: relative;
			margin: 0 auto;
			width: 170rpx;
			height: 170rpx;
			border-radius: 50%;
			overflow: hidden;
			& image:nth-child(1){
				width: 100%;
				height: 100%;
			}
			& image:nth-child(2){
				position: absolute;
				bottom: 12rpx;
				left: 100rpx;
				width: 58rpx;
				height: 58rpx;
			}
		}
		.data_info{
			.data_info_item{
				margin: 80rpx 0;
				font-size: 30rpx;
				color: #999;
				display: flex;
				padding-right: 40rpx;
				input {
					font-size: 30rpx;
					width: 400rpx;
				}
				.nickname{
					// margin-right: 112rpx;
					width: 35%;
					flex-shrink: 0;
				}
				.communityname{
					margin-right: 30rpx;
				}
				.user_name{
					color: #333;
				}
				.community_name{
					color: #333;
				}
			}
		}
		.save_btn{
			margin-top: 200rpx;
			width: 670rpx;
			height: 80rpx;
			line-height: 80rpx;
			color: #fff;
			text-align: center;
			background-color: #2AABAD;
			border-radius: 45rpx;
			font-size: 35rpx;
			
		}
	}
	.ewm_box{
		width: 600rpx;
		height: 600rpx;
		margin: 0 auto;
		background-color: #249B9D;
		transform: translateX(-24rpx);
		box-sizing: border-box;
		padding: 20rpx 0;
		// border-radius: 50rpx;
	}
	.ewm_box_txt{
		color: white;
		font-size: 30rpx;
		text-align: center;
	}
	.ewm_box_img{
		width: 400rpx;
		height: 400rpx;
		margin: 0 auto;
		display: block;
		margin-top: 60rpx;
	}
</style>
